﻿using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using Common;

namespace ImageProcessing.Storage
{
    public class Wp7ImageArchiver : BaseImageArchiver
    {
        protected override Stream CreateStorageFileStream(string fileName)
        {
            using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isolatedStorage.FileExists(fileName))
                    isolatedStorage.DeleteFile(fileName);
            }

            return IsolatedStorageFile.GetUserStoreForApplication().CreateFile(fileName);
        }

        protected override Stream OpenStorageFileStream(string fileName)
        {
            return IsolatedStorageFile.GetUserStoreForApplication().OpenFile(fileName, FileMode.Open);
        }

        protected override List<string> GetRawFilesListing()
        {
            using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                return isolatedStorage.GetFileNames("*.raw").ToList();
            }
        }
    }
}
